Skip to content

Conversation

jeremymeng
Copy link
Member

@jeremymeng jeremymeng commented Oct 4, 2025

Currently getHeadersOrUndefined incorrectly assumes that the ApnsHeaders parsed from XML is always an array. However, for single XML element the XML parser gives back an object instead. This change ensures we are iterating over an array.

One alternative approach is to add an option to core-xml specifying whether to treat certain single xml elements as an object or the single item of an array. Our underlying XML parser fast-xml-parser allows passing in a isArray: (name, jpath, isLeafNode, isAttribute) => boolean predicate but it is specific to fast-xml-parser and needs more discussion on how to properly expose it in core-xml. For this targeted scenario, it is good enough to check whether the parsed result is an array. This package uses same pattern in other places too, for example, https://github.com/Azure/azure-sdk-for-js/blob/953fcf9f84b/sdk/notificationhubs/notification-hubs/src/serializers/notificationHubJobSerializer.ts#L61

…ionDescription

Currently `getHeadersOrUndefined` incorrectly assumes that the `ApnsHeaders` parsed from XML is always an array. However, for single XML element the XML parser gives back an object instead. This change ensures we are iterating over an array.
@Copilot Copilot AI review requested due to automatic review settings October 4, 2025 00:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a TypeError in the notification-hubs SDK when parsing AppleTemplateRegistrationDescription with a single APNS header. The XML parser returns an object for single elements instead of an array, causing iteration errors.

  • Fixed the getHeadersOrUndefined function to handle both array and single object cases
  • Added test coverage for the single APNS header scenario

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/serializers/registrationSerializer.ts Updated function signature and logic to handle both array and object types for APNS headers
test/internal/unit/registrationSerializer.spec.ts Added test constant and test case for single APNS header scenario

@jeremymeng
Copy link
Member Author

/check-enforcer override

@jeremymeng jeremymeng closed this Oct 6, 2025
@jeremymeng jeremymeng reopened this Oct 6, 2025
@jeremymeng jeremymeng closed this Oct 6, 2025
@jeremymeng jeremymeng reopened this Oct 6, 2025
@jeremymeng jeremymeng merged commit 05a9860 into Azure:main Oct 6, 2025
17 checks passed
@jeremymeng jeremymeng deleted the nh/fix-app-template-reg branch October 6, 2025 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants